//
//  LiveViewController.swift
//  DYSwiftFramework
//
//  Created by huangdeyu on 2021/10/21.
//  Copyright © 2021 none. All rights reserved.
//

import UIKit

class LiveViewController: BasePageController,SubPageProtocol {
    
    var headerView:LiveSquareHeaderView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        addChildViewControllers()
        view.backgroundColor = UIColor.random
        print("直播viewDidLoad")
        headerView = LiveSquareHeaderView.init(titles: ["关注","精选","预告"],selectedIndex: 1)
        headerView?.onTap = {[weak self] (last,after) in
            self?.scrollTo(index: after, animated: false)
           
        }
        self.view.addSubview(headerView!)
        headerView?.snp.makeConstraints({ (make) in
            make.left.right.equalToSuperview()
            make.height.equalTo(40)
            make.top.equalToSuperview().offset(NAV_HEIGHT)
        })
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("直播viewWillAppear")
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("直播viewDidAppear")
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        print("直播viewWillDisappear")
    }
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        print("直播viewDidDisappear")
    }
    
    var visiable: Bool = false {
        willSet {
            if newValue {
                print("切换至直播")
            }
        }
    }

    func addChildViewControllers()  {
        let focus = LiveFocusViewController()
        let recommend = LiveSiftViewController.init()
        let live = LivePredictionViewController.init()
        setup(controllers: [focus,recommend,live], visibleIndex: 1)
    }

    override func onPageChanged(index: Int) {
        self.headerView?.changeIndex(index: index)
    }
}




